/*
 * TravisTester.java
 *
 * Created on March 26, 2007, 11:18 PM
 *
 */

package edu.byu.isys413.group1E;

import edu.byu.isys413.group1E.data.*;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/** Class to test the Other Services track for Milestone 3.
 *
 * @author Travis Kulbeth
 */
public class TravisTester {
    
    public static void main(String args[]) {
        try {
            Cache c = Cache.getInstance();
            Calendar cal = Calendar.getInstance();
            Date today = cal.getTime();
            SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
            String todayDate = fmt.format(today);
            
            /** Testing Backup Service Revenue Source*/
            System.out.println("===========================================================================");
            System.out.println("Testing Backup:\n");
            //create a new backup using the BackupHandler
            BackupBO bu = BackupHandler.getInstance().addNewBackup("00000110d80929f30000007f000002", "10.0");
            
            //save the BackupBO to the DB
            RSDAO_Factory.getInstance().getDAO("backup").save(bu);
            
            //display the contents of the created backup
            System.out.println("Backup saved ID: " + bu.getRevSrcID() + ", " + bu.getType() + ", " + bu.getDescription() +
                    ", $" + bu.getPrice() + "(should be $120), " + bu.getBeginDate() + ", " + bu.getEndDate() + ", " + bu.getBuSize());            
            
            //read from the Cache
            BackupBO bu2 = (BackupBO)RSDAO_Factory.getInstance().getDAO("backup").read(bu.getRevSrcID());
            System.out.println("Requested from Cache through read: bu==bu2 -> " + (bu == bu2));
            System.out.println("Backup retrieved ID: " + bu2.getRevSrcID() + ", " + bu2.getType() + ", " + bu2.getDescription() +
                    ", $" + bu2.getPrice() + "(should be $120), " + bu2.getBeginDate() + ", " + bu2.getEndDate() + ", " + bu2.getBuSize());
            
            //update the backup with the handler
            BackupHandler.getInstance().updateBackup(bu2, "20.0", "00000110d80929f30000007f000002");
            RSDAO_Factory.getInstance().getDAO("backup").save(bu2);
            
            //clear the cache and read the backup from the db as if reading from a previous transaction (using the RS_Handler)
            c.clear();
            String rsType = RS_Handler.getInstance().getRSType(bu2.getRevSrcID());
            BackupBO bu3 = (BackupBO)RSDAO_Factory.getInstance().getDAO(rsType).read(bu2.getRevSrcID());            
            System.out.println("Updated Backup retrieved directly from DB: " + bu3.getRevSrcID() + ", " + bu3.getType() + ", " + bu3.getDescription() +
                    ", \n\t$" + bu3.getPrice() + " (should now be $240), " + bu3.getBeginDate() + ", " + bu3.getEndDate() + ", " + bu3.getBuSize());

            /** Testing Service/Repair Revenue Source*/
            System.out.println("===========================================================================");
            System.out.println("Testing SvcRepair:\n");
            SvcRepairBO srPhys = SvcRepairHandler.getInstance().newSvcRepair("P1002", null, "00000110d7f8f1430000007f000002", "CustPhone", "3.0","150.0", "0000011106a3cc390000007f000002");
            RSDAO_Factory.getInstance().getDAO("repair").save(srPhys);
            SvcRepairBO srConc = SvcRepairHandler.getInstance().newSvcRepair("C1003", "2005-01-15", "00000110d7f8f1430000007f000002", "Email", "4.0","200.00", "0000011106a3cc390000007f000002");
            RSDAO_Factory.getInstance().getDAO("repair").save(srConc);            
            
            //Read the Physical SvcRepair from the Cache
            SvcRepairBO srPhys2 = (SvcRepairBO)RSDAO_Factory.getInstance().getDAO("repair").read(srPhys.getRevSrcID());
            System.out.println("SrPhys Requested from Cache through read: srPhys==srPhys2 -> " + (srPhys == srPhys2));
            System.out.println("Physical object repair retrieved ID: " + srPhys2.getRevSrcID() + ", " + srPhys2.getType() + ", " + srPhys2.getDescription() +
                    ", $" + srPhys2.getPrice() + ", \n\twarranty: " + srPhys2.isCoveredByWarranty() + ", labor hours: " + srPhys2.getLaborHrs() + ", on product: " + srPhys2.getProduct().getSKU() + 
                    "\n\t, completed: " + srPhys2.getCompleteDate() + ", picked up: "  + srPhys2.getPickUpDate() + ", last notice: " + 
                    srPhys2.getLastNoticeDate() + ", \n\trepaired by employee: " + srPhys2.getEmployee().getEmpFullName() + ", started: " + srPhys2.getStartDate() +
                    ", cust contact method: " + srPhys2.getContactMethod());
            
            //Read the Conceptual SvcRepair from the Cache
            SvcRepairBO srConc2 = (SvcRepairBO)RSDAO_Factory.getInstance().getDAO("repair").read(srConc.getRevSrcID());
            System.out.println("SrConc Requested from Cache through read: srConc==srConc2 -> " + (srConc == srConc2));
            System.out.println("Conceptual object repair retrieved ID: " + srConc2.getRevSrcID() + ", " + srConc2.getType() + ", " + srConc2.getDescription() +
                    ", $" + srConc2.getPrice() + ", \n\twarranty: " + srConc2.isCoveredByWarranty() + ", labor hours: " + srConc2.getLaborHrs() + ", on product: " + srConc2.getProduct().getSKU() + 
                    "\n\t, completed: " + srConc2.getCompleteDate() + ", picked up: "  + srConc2.getPickUpDate() + ", last notice: " + 
                    srConc2.getLastNoticeDate() + ", \n\trepaired by employee: " + srConc2.getEmployee().getEmpFullName() + ", started: " + srConc2.getStartDate() +
                    ", cust contact method: " + srConc2.getContactMethod());
            
            //update the srPhys with the handler
            SvcRepairHandler.getInstance().updateSvcRepair(srPhys, "2007-6-29", "2007-7-14", "2007-7-10", "250.00", "6.5");
            RSDAO_Factory.getInstance().getDAO("repair").save(srPhys);
            
            //clear the cache and read the updated srPhys as if reading from a transaction line
            c.clear();
            SvcRepairBO srPhys3 = (SvcRepairBO)RSDAO_Factory.getInstance().getDAO(RS_Handler.getInstance().getRSType(srPhys.getRevSrcID())).read(srPhys.getRevSrcID());            
            System.out.println("Updated Physical object repair retrieved ID: " + srPhys3.getRevSrcID() + ", " + srPhys3.getType() + ", " + srPhys3.getDescription() +
                    ", $" + srPhys3.getPrice() + ", \n\twarranty: " + srPhys3.isCoveredByWarranty() + ", labor hours: " + srPhys3.getLaborHrs() + ", on product: " + 
                    srPhys3.getProduct().getSKU() + ", completed: " + srPhys3.getCompleteDate() + ", picked up: "  + srPhys3.getPickUpDate() + ", last notice: " + 
                    srPhys3.getLastNoticeDate() + ", \n\trepaired by employee: " + srPhys3.getEmployee().getEmpFullName() + ", started: " + srPhys3.getStartDate() +
                    ", cust contact method: " + srPhys3.getContactMethod());
            
            
        }catch(Exception e) {
            e.printStackTrace();
        }
    }//main
}
